package com.example.linuxchat;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;


import androidx.appcompat.app.AppCompatActivity;

import com.example.linuxchat.bean.User;

import java.util.ArrayList;
import java.util.List;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        // 设置没有标题栏
//        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash);
        RelativeLayout layoutSplash=(RelativeLayout) findViewById(R.id.activity_splash);
        AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f,1.0f);
        alphaAnimation.setDuration(2000);//设置动画播放时长1000毫秒（1秒）
        layoutSplash.startAnimation(alphaAnimation);

        //设置动画监听
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }
            //动画结束
            @Override
            public void onAnimationEnd(Animation animation) {
                    isLogin();
            }
            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
    }

    private void isLogin(){
        //验证用户是否登入过，页面的跳转
        SharedPreferences sp=SplashActivity.this.getSharedPreferences("user_info", Context.MODE_PRIVATE);
        String id=sp.getString("id",null);
        String name=sp.getString("nickname",null);
        String imageUrl=sp.getString("url",null);
        if(TextUtils.isEmpty(id)){
            Intent intent=new Intent(SplashActivity.this,MainActivity.class);
            startActivity(intent);
        }else{
            User user=new User();
            user.setId(id);
            user.setNickname(name);
            user.setUrl(imageUrl);
            Intent intent=new Intent(SplashActivity.this,ChatActivity.class);
            intent.putExtra("user",user);
            startActivity(intent);
        }
        finish();
    }

}
